<?php
class NodeAction extends BaseAction {
	
	/**
	 * 节点列表
	 *
	 */
	function index(){
		$button[0]['href'] = U("Node/add");
		$button[0]['text'] = L('node_add');
		$this->assign('button', $button);
		$this->assign('ur_here', L("node_list"));
		$this->display();
	}
	
	/**
	 * 添加节点
	 *
	 */
	function add(){
		$button[0]['href'] = U("Node/Index");
		$button[0]['text'] = L('node_list');
		
		$node = array('id'=>0, 'name'=>'', 'parent'=>0, 'tag'=>'', 'sort'=>0, 'href'=>'', 'action'=>'toadd');
		$this->assign('node', $node);
		$this->assign('button', $button);
		$this->assign('option', $this->optionNode());
		$this->assign('ur_here', L("node_add"));
		$this->display();
	}
	
	/**
	 * 系统默认节点
	 *
	 */
	function defaults(){
		$button[0]['href'] = U("Node/add");
		$button[0]['text'] = L('node_add');
		$button[1]['href'] = U("Node/Index");
		$button[1]['text'] = L('node_list');
		$this->assign('button', $button);
		$this->assign('ur_here', L("node_default"));
		$this->display();
	}
	
	/**
	 * 显示OPTION的节点下拉框
	 *
	 * @param int $thisNode
	 * @return string
	 */
	private function optionNode($thisNode=0){
		$node = D("Node")->nodeList(true, false);
		$option = '';
		foreach($node AS $nd){
			if($nd['id'] == $thisNode){
				$option .= "<option value='".$nd["id"]."' selected>".$nd["name"]."</option>";
			}else{
				$option .= "<option value='".$nd["id"]."'>".$nd["name"]."</option>";
			}
			foreach ($nd['child'] AS $cd){
				if($cd['id'] == $thisNode){
					$option .= "<option value='".$cd["id"]."' selected>".str_repeat("&nbsp;", 2).$cd["name"]."</option>";
				}else{
					$option .= "<option value='".$cd["id"]."'>".str_repeat("&nbsp;", 2).$cd["name"]."</option>";
				}
			}
		}
		return $option;
	}
}
?>